<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="~{common::css}"></div>
    <link rel="stylesheet" href="../static/lib/editor_markdown/css/editormd.min.css"
          th:href="@{/lib/editor_markdown/css/editormd.min.css}">
    <title>博客发布</title>
</head>
<body class="m-about">
<!--导航-->
<div th:replace="~{common::menu(1)}"></div>
<!--二级导航-->
<div class="ui  attached pointing menu" >
    <div class="ui  container">
        <div class="right menu" >
            <a th:href="@{/admin/toBlogAdd}"  class=" ui    inverted green  button" >发布</a>
            <a th:href="@{/admin/toBlogManage/{current}(current=1)}" class=" ui  button" >管理</a>
        </div>
    </div>
</div>
<!--中间内容-->
<div class="m-padded-tb-big m-container">
    <div class="ui container">
        <form  id="blogAdd" th:action="@{/admin/insertBlog}" class="ui form" method="post">
            <input type="hidden" name="published">
            <div class="   field">
                <div class="ui left labeled input">
                    <div class=" ui selection  compact  dropdown teal basic label">
                        <input type="hidden" value="原创" >

                        <div class=" text m-text-spaced " >标题</div>

                    </div>
                    <input type="text" name="title" placeholder="请输入标题" autocomplete="off"  >
                </div>
            </div>
            <div class="field">
                <div id="md-content" style="z-index: 1 !important;">
                <textarea name="content"   style="display: none" >
                </textarea>
            </div>
                <div class="required field">
                    <div id="md-description" style="z-index: 1 !important;">
                        <textarea name="description"  placeholder="请对这篇博客简单简单描述..." maxlength="300"></textarea>
                    </div>
                    <input type="hidden" name="views"  value="0">
                </div>


            </div>
            <!--分类和标签选项-->
            <div class="two fields">
                <div class="field">
                    <div class="ui left labeled action input">
                        <label  class="ui compact teal basic label">分类</label>
                        <div class="ui fluid  selection dropdown">
                            <input type="hidden" name="typeId" >
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div  th:each="type : ${typeList}" th:data-value="${type.getId()}" th:text="${type.getName()}"  class="item" data-value="1">错误日志</div>

                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label  class="ui compact teal basic label">标签</label>
                        <div class="ui fluid  selection multiple search  dropdown">
                            <input type="hidden" name="tagIds" >
                            <i class="dropdown icon"></i>
                            <div class="default text">可选择多标签发布</div>
                            <div class="menu">
                                <div th:each="tag : ${tagList}" th:data-value="${tag.getId()}" th:text="${tag.getName()}"  class="item" data-value="1">Java</div>

                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="field">
                <div class="ui left labeled input">
                    <label  class="ui teal basic label">首图</label>
                    <input type="text" name="firstPicture" placeholder="首图引用地址" >
                </div>

            </div>
            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend" class="hidden"  >
                        <label for="recommend" style="color: #aeecac">推荐</label>
                    </div>
                </div>

            <div class="field">
                <div class="ui checkbox">
                    <input type="checkbox" id="shareInfo" name="shareStatement" class="hidden" >
                    <label for="shareInfo" style="color: #aeecac">转载</label>
                </div>
            </div>
            <div class="field">
                <div class="ui checkbox">
                    <input type="checkbox" id="appreciation" name="appreciation" class="hidden" >
                    <label for="appreciation" style="color: #aeecac">赞赏</label>
                </div>
            </div>

            <div class="field">
                <div class="ui  checkbox">
                    <input type="checkbox" id="comment" name="commentabled"  class="hidden"  >
                    <label for="comment" style="color: #aeecac">评论</label>
                </div>
            </div>
            </div>
            <div class="ui error message">
            </div>
            <div class="ui right aligned container">
                <button  type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button  type="button" id="save" class="ui secondary button">保存</button>
                <button  type="button" id="published" class="ui teal button" >发布</button>

            </div>
        </form>
    </div>
</div>
<!--底部 footer-->
<div th:replace="~{common::footer}"></div>


<script src="../static/js/jquery-3.5.1.js" th:src="@{/js/jquery-3.5.1.js}"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<script src="../static/lib/editor_markdown/editormd.min.js" th:src="@{/lib/editor_markdown/editormd.min.js}"></script>


    <script>
        //markdown编辑器初始化
        let contentEditor;
        $(function (){
            contentEditor = editormd("md-content",{
                width : "100%",
                height : 640,
                syncScrolling: "single",
                path : "/lib/editor_markdown/lib/"
            });
        });

        $('.menu.toggle').click(function (){
            $('.m-item').toggleClass('m-mobile-hide');

        });
        $('.ui.dropdown').dropdown({
            on : 'hover',
        });
        $('.ui.form').form({
            fields : {
                 title : {
                    identifier : 'title',
                   rules : [{
                        type : 'empty',
                      prompt : '标题：请输入博客标题'
                   }]
                 },
              content : {
                    identifier : 'content',
                    rules : [{
                        type : 'empty',
                        prompt : '内容：请输入博客内容'
                    }]
                },
                type : {
                    identifier : 'typeId',
                    rules : [{
                        type : 'empty',
                        prompt : '类型：请输入博客类型'
                    }]
                },
                tag : {
                    identifier : 'tagIds',
                    rules : [{
                        type : 'empty',
                        prompt : '标签：请输入博客标签'
                    }]
                },
                indexPicture : {
                identifier : 'firstPicture',
                    rules : [{
                    type : 'empty',
                    prompt : '地址：请输入博客图片地址'
                }]
            }
            }
        });

        $('#save').click(function () {     //点击保存，修改发布状态为false
            $('[name="published"]').val(false);
            $('#blogAdd').submit();
        });


        $('#published').click(function () {   //点击发布，修改发布状态为true
            $('[name="published"]').val(true);
            $('#blogAdd').submit();
        });
    </script>
</body>

</html>